package com.zfzs.post.modules.finance.service.impl;

import com.zfzs.post.modules.agent.domain.AgentVerified;
import com.zfzs.post.modules.agent.domain.WithdrawOrder;
import com.zfzs.post.modules.agent.service.AgentVerifiedService;
import com.zfzs.post.modules.agent.service.WithdrawOrderService;
import com.zfzs.post.modules.agent.service.dto.WithdrawOrderQueryCriteria;
import com.zfzs.post.modules.finance.service.WithdrawOrderWebService;
import com.zfzs.post.modules.finance.service.vo.WithdrawOrderVO;
import com.zfzs.post.utils.CloneUtils;
import com.zfzs.post.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wq
 * @date 2019/12/6 16:47
 * @description
 */
@Service
public class WithdrawOrderWebServiceImpl implements WithdrawOrderWebService {

    @Autowired
    private WithdrawOrderService withdrawOrderService;


    @Autowired
    private AgentVerifiedService agentVerifiedService;

    @Override
    public Map<String, Object> findOrderPage(WithdrawOrderQueryCriteria criteria, Integer page, Integer size) {


        Long userId = SecurityUtils.getUserId();

        if(!userId.equals(1L)){
            criteria.setChannelId(1L);
        }
        Page<WithdrawOrder> orderPage = withdrawOrderService.findOrderPage(criteria, page, size);

        List<WithdrawOrderVO> vos= CloneUtils.batchClone(orderPage.getContent(),WithdrawOrderVO.class);

        for (WithdrawOrderVO vo : vos) {
            AgentVerified byAgentId = agentVerifiedService.findByAgentId(vo.getAgentId());

            vo.setName(byAgentId.getCardName());

        }
        Map<String,Object> map=new HashMap<>(2);
        map.put("content", vos);
        map.put("totalElements", orderPage.getTotalElements());
        return map;
    }
}
